package axdoc.dao.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;

public class BusinessEventUtil {

	private static Logger logger = LoggerFactory.getLogger(BusinessEventUtil.class);

	BusinessEventDao businessEventDao;

	public BusinessEventDao getBusinessEventDao() {
		return businessEventDao;
	}

	public void setBusinessEventDao(BusinessEventDao businessEventDao) {
		this.businessEventDao = businessEventDao;
	}

	public static Map<Integer, List<EventType>> businessEvents = new HashMap<Integer, List<EventType>>();

	public static List<BusinessTypeConfig> businessTypes = new ArrayList<BusinessTypeConfig>();

	public void init() {
		logger.info("[初始化业务类型及事件类型][start]");
		List<BusinessTypeConfig> bts = businessEventDao.queryBusinessTypes();
		if (bts != null && bts.size() > 0) {
			for (BusinessTypeConfig btc : bts) {
				businessTypes.add(btc);
				businessEvents.put(btc.getBusinessId(), businessEventDao.queryEventTypes(btc.getBusinessId()));
			}
		}
		logger.info("[初始化业务类型及事件类型][end][" + (JSON.toJSONString(businessTypes)) + "]");
	}

	public List<EventType> getEventTypes(int businessType) {
		return BusinessEventUtil.businessEvents.get(businessType);
	}
}
